<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <link rel="stylesheet" type="text/css" href="../../css/weui.min.css" />
    <link rel="stylesheet" type="text/css" href="../../css/jquery-weui.min.css" />
    <link rel="stylesheet" type="text/css" href="../../css/index.css" />
    <link rel="stylesheet" type="text/css" href="../../css/order.css" />
    <link rel="stylesheet" type="text/css" href="https://at.alicdn.com/t/font_546019_o8qxm6fupb0ggb9.css" />
    <title>报价单</title>
    <script src="../../js/jquery-2.1.4.js" type="text/javascript" charset="utf-8"></script>
    <script src="../../js/jquery-weui.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="../../js/baseConfig.js" type="text/javascript" charset="utf-8"></script>
    <script src=" http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
</head>
<style type="text/css">
    .weui-uploader__file_status::before {
        background-color: rgba(0, 0, 0, 0);
    }
</style>

<body>
    <!--<div id="header">
			<div class="header-title" style="position: fixed;top: 0;">
				<img src="../../img/left.png" class="left" />
				<span>报价单</span>
			</div>
		</div>-->
    <!--若无报价单就显示这个上传报价单-->
    <div class="invoice_warp" style="margin-top: 0;">
        <div class="weui-cells weui-cells_form">
            <form method="post" id="form1">
                <div class="weui-cell" style="padding: 0;">
                    <div class="weui-cell__bd">
                        <div class="weui-uploader__bd">
                            <ul class="weui-uploader__files">

                            </ul>
                            <div class="weui-uploader__input-box">
                                <input id="uploaderInput" name="offerSheetFile" class="weui-uploader__input js_file" type="file" accept="image/*">
                            </div>
                        </div>
                    </div>
                </div>
            </form>
        </div>

        <div class="demos-content-padded" style="display: none">
            <a href="javascript:;" class="weui-btn weui-btn_primary">确定</a>
        </div>
    </div>
    <!--若有报价单则显示报价单图片-->
    <div class="imgWarp" style="display: none;margin-top: 0;">
        <img src="../../img/photo.png" />
    </div>
    <div class="weui-gallery" style="display: none">
        <span class="weui-gallery__img"></span>
    </div>
</body>
<script type="text/javascript">
    $(document).ready(function() {
        baseConfig.historyBack()
        $.ajax({
            type: "get",
            url: baseConfig.localHttp + "weChatApi/fgclient/getOffer",
            async: false,
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded'
            },
            data: {
                clientId: baseConfig.login(),
                orderNo: baseConfig.GetQueryString("orderNo")
            },
            success: function(data) {
                $.hideLoading();
                console.log(data)
                var status = baseConfig.GetQueryString("status")
                if (data.code == 100) {
                    //若有报价单则直接显示报价单	
                    if (status == 1) {
                        $(".invoice_warp").hide()
                        $(".imgWarp").show()
                        $(".demos-content-padded").hide()
                        $(".imgWarp img").attr("src", baseConfig.imglocalHttp + data.content)
                        $(".imgWarp img").on("click", function() {
                            var imgsurl = [];
                            imgsurl[0] = this.src;
                            var nowurl = this.src;
                            wx.previewImage({
                                current: nowurl,
                                urls: imgsurl
                            });
                        })
                    } else {
                    	if(!data.content){
                    		$(".weui-btn_primary").html("确定")
                    	}else{
                    		$(".weui-btn_primary").html("重新上传")
                    	}
                        $(".demos-content-padded").show()
                        baseConfig.singleImgupload()
                        $(".weui-btn").on("click", function() {
                            var formData = new FormData($("#form1")[0])
                            formData.append("orderNo", baseConfig.GetQueryString("orderNo"));
                            $.ajax({
                                type: "post",
                                url: baseConfig.localHttp + "weChatApi/fgclient/uploadOfferSheet",
                                data: formData,
                                contentType: false,
                                processData: false,
                                success: function(data) {
                                    console.log(data)
                                    if (data.code == 100) {
                                        $.toptip("图片上传成功", 1200, 'success')
                                        setTimeout(function() {
                                            window.location.replace(document.referrer)
                                                //												location.href = "mine.html"
                                                //												location.href = "uploadInvoice.html?orderNo="+baseConfig.GetQueryString("orderNo")
                                        }, 1200)
                                    } else {

                                    }
                                },
                                error: function() {
                                    //										location.href = "uploadInvoice.html?orderNo="+baseConfig.GetQueryString("orderNo")
                                }
                            })
                        })
                    }
                } else {
                    //若没有报价单则页面展示上传报价单
                    var status = baseConfig.GetQueryString("status")
                    if (status == 1) {
                        $(".invoice_warp").hide()
                        $.toast(data.content, "cancel");
                    } else {
                        $(".invoice_warp").show()
                        $(".imgWarp").hide()
                        $(".demos-content-padded").show();
                        baseConfig.singleImgupload()
                        $(".weui-btn").on("click", function() {
                            var formData = new FormData($("#form1")[0])
                            formData.append("orderNo", baseConfig.GetQueryString("orderNo"));
                            $.ajax({
                                type: "post",
                                url: baseConfig.localHttp + "weChatApi/fgclient/uploadOfferSheet",
                                data: formData,
                                contentType: false,
                                processData: false,
                                success: function(data) {
                                    console.log(data)
                                    if (data.code == 100) {
                                        $.toptip("图片上传成功", 1200, 'success')
                                        setTimeout(function() {
                                            //												window.location.replace(document.referrer)
                                            location.href = "mine.html"
                                        }, 1200)
                                    } else {

                                    }
                                },
                                error: function() {
                                    $.hideLoading();
                                    $.toast("请求失败", "cancel");
                                }
                            })
                        })
                    }

                }
            },
            error: function() {
                $.hideLoading();
                $.toast("请求失败", "cancel");
            }
        })
    })
</script>

</html>